package com.mall.order.services;

import com.mall.order.CancelOrderService;
import com.mall.order.constant.OrderRetCode;
import com.mall.order.constants.OrderConstants;
import com.mall.order.dal.entitys.Order;
import com.mall.order.dal.persistence.OrderMapper;
import com.mall.order.dto.CancelOrderRequest;
import com.mall.order.dto.CancelOrderResponse;
import com.mall.order.dto.OrderDto;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author TL
 * @created Date:2020/12/21 Time:19:18
 **/
@Service(interfaceClass = CancelOrderService.class)
@Component
public class CancelOrderServiceImpl implements CancelOrderService {

    @Autowired
    OrderMapper orderMapper;

    @Override
    public CancelOrderResponse cancelOrderById(CancelOrderRequest request) {
        String orderId = request.getOrderId();
        Order order = new Order();
        order.setOrderId(orderId);
        order.setStatus(OrderConstants.ORDER_STATUS_TRANSACTION_CANCEL);
        CancelOrderResponse cancelOrderResponse = new CancelOrderResponse();
        int i = orderMapper.updateByPrimaryKeySelective(order);
        if (i != 1){
            cancelOrderResponse.setCode(OrderRetCode.DB_EXCEPTION.getCode());
            cancelOrderResponse.setMsg(OrderRetCode.DB_EXCEPTION.getMessage());
            return cancelOrderResponse;
        }
        cancelOrderResponse.setCode(OrderRetCode.SUCCESS.getCode());
        cancelOrderResponse.setMsg(OrderRetCode.SUCCESS.getMessage());

        return cancelOrderResponse;
    }
}
